package com.hinnotek.amoeba.viewmodels


import androidx.lifecycle.viewModelScope
import com.hinnotek.amoeba.base.BaseBean
import com.hinnotek.amoeba.bean.old.*
import com.hinnotek.amoeba.repo.NoticeRepo
import com.lee.common.base.BaseViewModel
import com.lee.common.network.net.StateLiveData
import dagger.hilt.android.lifecycle.HiltViewModel
import kotlinx.coroutines.launch
import okhttp3.RequestBody
import javax.inject.Inject

@HiltViewModel
class NoticeViewModel @Inject constructor(private val repository: NoticeRepo) :
    BaseViewModel() {

    private val installByUserIdData = StateLiveData<MutableList<AmibaInstallPageByUserIdBean>>()
    private val projectListByOrgIdData = StateLiveData<MutableList<AmibaProjectListByOrgIdBean>>()
    private val amibaReimbursePageByUserIdData =
        StateLiveData<MutableList<AmibaReimbursePageByUserIdBean>>()
    private val sellPurchaseRequistionData =
        StateLiveData<MutableList<SellPurchaseRequistionBean>>()
    private val amibaTemporaryePageByUserIdData =
        StateLiveData<MutableList<AmibaTemporaryePageByUserIdBean>>()
    private val companyPurchaseByUserIdData =
        StateLiveData<MutableList<CompanyPurchaseByUserIdBean>>()
    private val companyPhonePayPageByUserIdData =
        StateLiveData<MutableList<CompanyPhonePayPageByUserIdBean>>()

    private val amibaInstallByIdData = StateLiveData<AmibaInstallByIdBean>()
    private val baseData = StateLiveData<BaseBean>()


    /**
     * app端阿米巴安装历史申请接口
     */
    fun getAmibaInstallPageForHistory(
        applyUserId: Int,
        approvalUserId: String?,
        pageNo: Int,
        pageSize: Int
    ): StateLiveData<MutableList<AmibaInstallPageByUserIdBean>> {
        viewModelScope.launch {
            repository.getAmibaInstallPageForHistory(
                applyUserId,
                approvalUserId,
                pageNo,
                pageSize, installByUserIdData
            )
        }
        return installByUserIdData
    }

    /**
     * app端阿米巴安装历史申请接口
     */
    fun getAmibaPayPageForHistory(
        applyUserId: Int,
        approvalUserId: String?,
        pageNo: Int,
        pageSize: Int
    ): StateLiveData<MutableList<AmibaProjectListByOrgIdBean>> {
        viewModelScope.launch {
            repository.getAmibaPayPageForHistory(
                applyUserId,
                approvalUserId,
                pageNo,
                pageSize, projectListByOrgIdData
            )
        }
        return projectListByOrgIdData
    }

    /**
     * app端阿米巴报销历史申请接口
     */
    fun getAmibaReimbursePageForHistory(
        applyUserId: Int,
        approvalUserId: String?,
        pageNo: Int,
        pageSize: Int
    ): StateLiveData<MutableList<AmibaReimbursePageByUserIdBean>> {
        viewModelScope.launch {
            repository.getAmibaReimbursePageForHistory(
                applyUserId,
                approvalUserId,
                pageNo,
                pageSize, amibaReimbursePageByUserIdData
            )
        }
        return amibaReimbursePageByUserIdData
    }

    /**
     * app端阿米巴临时缴费续费历史申请接口
     */
    fun getAmibaTemporaryePageForHistory(
        applyUserId: Int,
        approvalUserId: String?,
        pageNo: Int,
        pageSize: Int
    ): StateLiveData<MutableList<AmibaTemporaryePageByUserIdBean>> {
        viewModelScope.launch {
            repository.getAmibaTemporaryePageForHistory(
                applyUserId,
                approvalUserId,
                pageNo,
                pageSize, amibaTemporaryePageByUserIdData
            )
        }
        return amibaTemporaryePageByUserIdData
    }

    /**
     * app端阿米巴临时缴费续费历史申请接口
     */
    fun getCompanyPurchasePageForHistory(
        applyUserId: Int,
        approvalUserId: String?,
        pageNo: Int,
        pageSize: Int
    ): StateLiveData<MutableList<CompanyPurchaseByUserIdBean>> {
        viewModelScope.launch {
            repository.getCompanyPurchasePageForHistory(
                applyUserId,
                approvalUserId,
                pageNo,
                pageSize, companyPurchaseByUserIdData
            )
        }
        return companyPurchaseByUserIdData
    }

    /**
     * app端阿米巴临时缴费续费历史申请接口
     */
    fun getCompanyPhonePayPageForHistory(
        applyUserId: Int,
        approvalUserId: String?,
        pageNo: Int,
        pageSize: Int
    ): StateLiveData<MutableList<CompanyPhonePayPageByUserIdBean>> {
        viewModelScope.launch {
            repository.getCompanyPhonePayPageForHistory(
                applyUserId,
                approvalUserId,
                pageNo,
                pageSize, companyPhonePayPageByUserIdData
            )
        }
        return companyPhonePayPageByUserIdData
    }

    /**
     * app端阿米巴采购历史申请接口
     */
    fun getAmibaPurchasePageForHistory(
        applyUserId: Int,
        approvalUserId: String?,
        pageNo: Int,
        pageSize: Int
    ): StateLiveData<MutableList<SellPurchaseRequistionBean>> {
        viewModelScope.launch {
            repository.getAmibaPurchasePageForHistory(
                applyUserId,
                approvalUserId,
                pageNo,
                pageSize, sellPurchaseRequistionData
            )
        }
        return sellPurchaseRequistionData
    }

    /**
     * app端阿米巴采购历史申请接口
     */
    fun getAmibaPurchaseApproval(
        amibaPurchaseId: Int,
        approvalState: Int,
        noticeId: Int,
        refusalReasons: String
    ): StateLiveData<BaseBean> {
        viewModelScope.launch {
            repository.amibaPurchaseApproval(
                amibaPurchaseId,
                approvalState,
                noticeId,
                refusalReasons, baseData
            )
        }
        return baseData
    }

    fun getNoticeDetailById(noticeId: Int):StateLiveData<AmibaInstallByIdBean> {
        viewModelScope.launch {
            repository.getNoticeDetailById(noticeId,amibaInstallByIdData)
        }
        return amibaInstallByIdData
    }

    fun getAmibaInstallApproval(amibaInstallId: Int, approvalState: Int, noticeId: Int): StateLiveData<BaseBean> {
        viewModelScope.launch {
            repository.getAmibaInstallApproval(amibaInstallId,approvalState,noticeId,baseData)
        }
        return baseData
    }

    fun getAmibaPayApproval(amibaInstallId: Int, approvalState: Int, noticeId: Int): StateLiveData<BaseBean> {
        viewModelScope.launch {
            repository.amibaPayApproval(amibaInstallId,approvalState,noticeId,baseData)
        }
        return baseData
    }
    
    fun getCompanyPhonePayApproval(companyPhonePayId: Int, approvalState: Int, noticeId: Int): StateLiveData<BaseBean> {
        viewModelScope.launch {
            repository.getCompanyPhonePayApproval(companyPhonePayId,approvalState,noticeId,baseData)
        }
        return baseData
    }
    
    fun getCompanyPurchaseApproval(companyPurchaseId: Int, approvalState: Int, noticeId: Int): StateLiveData<BaseBean> {
        viewModelScope.launch {
            repository.getCompanyPurchaseApproval(companyPurchaseId,approvalState,noticeId,baseData)
        }
        return baseData
    }

    fun getAmibaTemporaryApproval(amibaTemporaryId: Int, approvalState: Int, noticeId: Int) : StateLiveData<BaseBean>{
        viewModelScope.launch {
            repository.getAmibaTemporaryApproval(amibaTemporaryId,approvalState,noticeId,baseData)
        }
        return baseData
    }

    fun getAmibaReimburseApproval(amibaReimburseId: Int, approvalState: Int, noticeId: Int, refusalReasons: String): StateLiveData<BaseBean> {
        viewModelScope.launch {
            repository.getAmibaReimburseApproval(amibaReimburseId,approvalState,noticeId,refusalReasons,baseData)
        }
        return baseData
    }

    private val allSysOrg = StateLiveData<MutableList<AllSysOrg>>()

    fun getAllSysOrg():StateLiveData<MutableList<AllSysOrg>> {
        viewModelScope.launch {
            repository.getAllSysOrg(allSysOrg)
        }
        return allSysOrg
    }

    private val noticePageByUserIdData = StateLiveData<MutableList<NoticePageByUserIdBean>>()

    fun getNoticePage(requestBody: RequestBody) :StateLiveData<MutableList<NoticePageByUserIdBean>>{
        viewModelScope.launch {
            repository.getNoticePage(requestBody,noticePageByUserIdData)
        }
        return noticePageByUserIdData
    }

    private val noticePageByUserIdData2 = StateLiveData<MutableList<NoticePageByUserIdBean>>()

    fun getNoticePageByUserId(requestBody: RequestBody) :StateLiveData<MutableList<NoticePageByUserIdBean>>{
        viewModelScope.launch {
            repository.getNoticePageByUserId(requestBody,noticePageByUserIdData2)
        }
        return noticePageByUserIdData2
    }

    fun getNoticePage2(searchId: Int, orgName: String, pageNo: Int, pageSize: Int) :StateLiveData<MutableList<NoticePageByUserIdBean>>{
        viewModelScope.launch {
            repository.getNoticePage2(searchId,orgName,pageNo,pageSize,noticePageByUserIdData2)
        }
        return noticePageByUserIdData2
    }

}